package models;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;

import play.data.validation.Required;
import play.db.jpa.Blob;
import play.db.jpa.Model;

@Entity
public class Ingredient extends Model {
	
	@Required
	public String name;
	
	@Required
	// calories per portion
	public int calories;
	
	@Required
	// price per portion
	public double price;
	
	@Required
	// portion in grams
	public int portion;
	
	public Blob icon;
	
	@Required
	@Enumerated (EnumType.STRING)
	public IngredientCategory category;
	
	public boolean isSelected(Salad salad){
		if (salad != null){
			for (Ingredient ing : salad.ingredients) {
				if (this.id == ing.id)
					return true;
			}
		}
		
		return false;
	}


	public String getPortionDescription() {
		return this.portion + " gr.";
	}
	
}
